package zhupf.test.proxyTest.jdkProxyTest;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKDynamicObject  implements InvocationHandler {

    // 被代理的对象
    private Object target;

    public JDKDynamicObject(){}

    public Object build(Object target){
        this.target = target;
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("JDK动态代理，前置处理");
        Object invoke = method.invoke(target, args);
        System.out.println("JDK动态代理，后置处理");
        return invoke;
    }

}
